import { defineEventHandler, getCookie, createError } from 'h3';
import scheduler from '../../utils/scheduler.js';

export default defineEventHandler(async (event) => {
  try {
    const userId = getCookie(event, 'userId');
    if (!userId) {
      throw createError({ statusCode: 401, statusMessage: 'Unauthorized' });
    }

    const tasks = scheduler.getActiveTasks();
    const presets = scheduler.getPresetExpressions();

    return {
      success: true,
      tasks: tasks,
      presets: presets
    };
  } catch (error) {
    console.error('获取定时任务失败:', error);
    throw createError({ statusCode: 500, statusMessage: 'Failed to get scheduled tasks' });
  }
});
